using System;
using System.Collections.Generic;
using UnityEngine;

namespace Gj
{
    public class SelectShowHelper : NodeHelper
    {
        public List<SelectShowItem> list;

        protected override BindDataType bindDataType => BindDataType.String;

        protected override void Init()
        {
            base.Init();
            foreach (var item in list)
            {
                var help = item.obj.GetComponent<NodeHelper>();
                if (help != null) BindEvent(help);
            }
        }

        protected override void BindData(string i)
        {
            GameObject obj = null;
            foreach (var item in list)
                if (item.key == i)
                {
                    obj = item.obj;
                    item.obj.SetActive(true);
                    var help = item.obj.GetComponent<NodeHelper>();
                    if (help != null)
                    {
                        child.Clear();
                        child.Add(help);
                        SetChildData(_data);
                    }
                }
                else
                {
                    if (obj != item.obj)
                        item.obj.SetActive(false);
                }
        }

        [Serializable]
        public class SelectShowItem
        {
            public string key;
            public GameObject obj;
        }
    }
}